package com.fpd.model.vo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fpd.constant.SystemConstant;
import com.fpd.enums.ErrorCode;
import com.fpd.model.ro.PageRO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @desc 返回前端结果集
 * @author wujiangbo
 * @date 2019年11月6日 上午11:20:06
 * @param <T>
 */
@ApiModel(description="返回结果集数据类型")
public class ResultVO<T> implements Serializable {

	private static final long serialVersionUID = -6517472455767655697L;

	/**
	 * 成功
	 */
	public static final String SUCCESS_CODE = "000";
	/**
	 * 失败
	 */
	public static final String ERROR_CODE = "002";

	@ApiModelProperty(value = "结果标识(000：成功；002：失败；其它编码：其它含义)")
	private String code = SUCCESS_CODE;

	@ApiModelProperty(value = "返回消息")
	private String message = SystemConstant.successMessage;

	@ApiModelProperty(value = "返回数据")
	private Map<String, Object> data = new HashMap<>();





	public ResultVO(List<T> list, int count) {
		this.data.put("list", list);
		this.data.put("count", count);

	}




	public ResultVO(List<T> list, int count, double pageSize) {
		this.data.put("list", list);
		this.data.put("count", count);
		this.data.put("pageSize", pageSize);
	}
//     新增
	public ResultVO(List<T> list, int count, PageRO pageSize,List<T> list2) {
		this.data.put("list", list);
		this.data.put("count", count);
		this.data.put("pageSize", pageSize.getPageSize());
		this.data.put("allGroupName", list2);
	}

	//返回校验
	public ResultVO(List<T> list, int count, String fileName,List<T> list2) {
		this.data.put("list", list);
		this.data.put("count", count);
		this.data.put("fileName", fileName);
		this.data.put("allGroupName", list2);
	}

	public ResultVO(List<T> list, int count, PageRO page) {
		this.data.put("list", list);
		this.data.put("count", count);
		this.data.put("pageSize", page.getPageSize());
		this.data.put("currentPage", page.getCurrentPage());
	}

	public ResultVO(List<T> list) {
		this.data.put("list", list);
	}

	public ResultVO(T t) {
		this.data.put("vo", t);
	}


	public ResultVO(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public ResultVO(ErrorCode errorCode) {
		this.code = errorCode.getCode();
		this.message = errorCode.getMessage();
	}

	public ResultVO(Map<String, Object> data, String code, String message) {
		this.data = data;
		this.code = code;
		this.message = message;
	}

	public ResultVO() {
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "ResultVO [code=" + code + ", message=" + message + ", data=" + data + "]";
	}
}
